﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using TCP服务器端;

namespace SearchServer
{
    class ClientManager
    {
        public static List<Socket> clientSockets = new List<Socket>();


        public static void BroadCastToClientSockets(string msg,int count)
        {
            Socket isNeedRemoveSocket = null;
            foreach(Socket socket in clientSockets)
            {
                if(!socket.Connected)
                {
                    isNeedRemoveSocket = socket;
                    continue;
                }
                byte[] data1 = BitConverter.GetBytes(count);
                byte[] data2 = Encoding.UTF8.GetBytes(msg);
                byte[] data = data1.Concat(data2).ToArray();
                socket.Send(data);
            }
            clientSockets.Remove(isNeedRemoveSocket);
        }

    }
}
